package erfgame.core.entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashSet;


import erfgame.core.AbstractIntIdObject;
import erfgame.core.word.Noun;

public class EntityType extends AbstractIntIdObject implements Serializable {
	private Noun name;
	
	private Collection<EntityType> childTypes;
	private Collection<EntityType> parentTypes;
	
	public EntityType( int id, Noun name ) {
		this( id, name, null );
	}

	public EntityType( int id, Noun name, Collection<EntityType> parentTypes ) {
		super( id );
		this.name = name;
		this.childTypes = new HashSet<EntityType>();
		setParentTypes( parentTypes );
	}
	
	public Noun getName() {
		return this.name;
	}
	
	public Collection<EntityType> getChildTypes() {
		return this.childTypes;
	}
	
	public Collection<EntityType> getParentTypes() {
		return this.parentTypes;
	}
	
	protected void setParentTypes( Collection<EntityType> parentTypes ) {
		this.parentTypes = parentTypes;
		if( parentTypes != null ) {
			for( EntityType parentType : parentTypes ) {
				parentType.addChildType( this );
			}
		}
	}
	
	protected void addParentType( EntityType parentType ) {
		this.parentTypes.add( parentType );
	}
	
	protected void addChildType( EntityType childType ) {
	    this.childTypes.add( childType );
	}
}
